package com.baomidou.ant.service.impl;

import com.baomidou.ant.entity.ApplyInfo;
import com.baomidou.ant.entity.ResumeInfo;
import com.baomidou.ant.mapper.ResumeInfoMapper;
import com.baomidou.ant.service.IResumeInfoService;
import com.baomidou.ant.vo.request.RequestListResumeVo;
import com.baomidou.ant.vo.response.ResponseListApplyInfoVo;
import com.baomidou.ant.vo.response.ResponseListResumeVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2022-09-20
 */
@Service
public class ResumeInfoServiceImpl extends ServiceImpl<ResumeInfoMapper, ResumeInfo> implements IResumeInfoService {
    @Value("${file.nginxIp}")
    private String nginxIp;

    @Override
    public ResumeInfo queryByUser(String userName, String userTel) {
        QueryWrapper<ResumeInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("apply_user_name",userName);
        queryWrapper.eq("user_tel",userTel);
        ResumeInfo resumeInfo=getOne(queryWrapper);
        return resumeInfo;
    }

    @Override
    public IPage<ResponseListResumeVo> listResume(RequestListResumeVo vo) {
        IPage<ResumeInfo> iPage=new Page<>(vo.getDisplayStart(),vo.getDisplayLength());
        QueryWrapper<ResumeInfo> queryWrapper=new QueryWrapper<>();
        if(ObjectUtils.isNotEmpty(vo.getApplyUserName_Send())){
            queryWrapper.like("apply_user_name",vo.getApplyUserName_Send());
        }
        if (ObjectUtils.isNotEmpty(vo.getIntentionPost_Send())){
            queryWrapper.like("intention_post",vo.getIntentionPost_Send());
        }
        if(ObjectUtils.isNotEmpty(vo.getTelephone_Send())){
            queryWrapper.like("user_tel",vo.getTelephone_Send());
        }
        queryWrapper.orderByDesc("create_time");
        int allTotal=list(queryWrapper).size();
        IPage<ResumeInfo> resumeIPage=page(iPage,queryWrapper);
        return resumeIPage.convert(resumeInfo -> {
            ResponseListResumeVo responseListResumeVo=new ResponseListResumeVo();
            BeanUtils.copyProperties(resumeInfo,responseListResumeVo);
            responseListResumeVo.setNginxIp(nginxIp);
            responseListResumeVo.setAllTotal(allTotal);
            return responseListResumeVo;
        });
    }
}
